#pragma one

#include <iostream>
#include <pthread.h>

namespace LockModule
{
    class Mutex
    {
    public:
        Mutex()
        {
            int n = pthread_mutex_init(&mutex, nullptr);
            (void *)n;
        }
        void lock()
        {
            pthread_mutex_lock(&mutex);
        }
        void unlock()
        {
            pthread_mutex_unlock(&mutex);
        }
        pthread_mutex_t *LockPtr()
        {
            return &mutex;
        }
        ~Mutex()
        {
            int n = pthread_mutex_destroy(&mutex);
        }

    private:
        pthread_mutex_t mutex;
    };
    class LockGuard
    {
    public:
        LockGuard(Mutex &mtx)
        :_mux(mtx)
        {
            _mux.lock();
        }
        ~LockGuard()
        {
            _mux.unlock();
        }

    private:
    Mutex &_mux;
    };
};
